package com.transformer.shobal;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import com.transformer.shobal.activitys.BaseActivity;
import com.transformer.shobal.activitys.canvas.CanvasActivity;
import com.transformer.shobal.activitys.media.MediaTestActivity;
import com.transformer.shobal.activitys.paint.PaintActivity;
import com.transformer.shobal.activitys.wigets.WigetsActivity;

public class MainActivity extends BaseActivity {
    /**
     * Called when the activity is first created.
     */
    View btn1;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        btn1 = findViewById(R.id.btn_1);
        btn1.setOnClickListener(onClickListener);
        findViewById(R.id.btn_2).setOnClickListener(onClickListener);
        findViewById(R.id.btn_3).setOnClickListener(onClickListener);
        findViewById(R.id.btn_4).setOnClickListener(onClickListener);
        findViewById(R.id.btn_5).setOnClickListener(onClickListener);
    }

    private View.OnClickListener onClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            btnClick(v);
        }
    };

    private void btnClick(View v){
        switch (v.getId()){
            case R.id.btn_1:
                Intent intent = new Intent(this, PaintActivity.class);
                startActivity(intent);
                break;
            case R.id.btn_2:
                Intent intent2 = new Intent(this, WigetsActivity.class);
                startActivity(intent2);
                break;
            case R.id.btn_3:
                Intent intent3 = new Intent(this, CanvasActivity.class);
                startActivity(intent3);
                break;
            case R.id.btn_4:
//                WindowManager windowManager = (WindowManager)getSystemService(this.WINDOW_SERVICE);
                WindowManager windowManager = (WindowManager)getApplication().getSystemService(this.WINDOW_SERVICE);
                WindowManager.LayoutParams params = new WindowManager.LayoutParams();
                params.width = 200;
                params.height = 200;
                params.format = PixelFormat.TRANSLUCENT;
//                params.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;//应用弹窗
//                params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;//桌面浮窗
                params.type = WindowManager.LayoutParams.TYPE_PHONE;//桌面浮窗
                params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;//后面窗口仍然可以处理点设备事件
                params.setTitle("Toast");
                TextView tv = new TextView(getApplicationContext());
                tv.setLayoutParams(params);
                tv.setBackgroundColor(Color.RED);
                tv.setText("this is a float window ");
                windowManager.addView(tv, params);
                break;
            case R.id.btn_5:
                Intent intent4 = new Intent(this, MediaTestActivity.class);
                startActivity(intent4);
                break;
            default:
        }
    }
}
